package cn.tedu.ivos.application.controller;

import cn.tedu.ivos.application.pojo.dto.ApplicationQuery;
import cn.tedu.ivos.application.pojo.dto.ApplicationSaveParam;
import cn.tedu.ivos.application.pojo.vo.ApplicationVO;
import cn.tedu.ivos.application.service.ApplicationService;
import cn.tedu.ivos.base.response.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.swing.plaf.PanelUI;
import java.util.List;

@Tag(name="申请模块")
@Slf4j
@RestController
@RequestMapping("/v1/application")
public class ApplicationController {
    @Autowired
    ApplicationService applicationService;

    @Operation(summary="新增申请单")
    @ApiOperationSupport(order = 10)
    @PostMapping("save")
    public JsonResult saveApplication(
            @Validated ApplicationSaveParam applicationSaveParam){
        log.debug("新增申请单,参数={}",applicationSaveParam);
        applicationService.saveApp(applicationSaveParam);
        return JsonResult.ok();
    }
    @Operation(summary = "查询申请单")
    @ApiOperationSupport(order = 20)
    @GetMapping("select")
    public JsonResult searchApplication(ApplicationQuery query){
        List<ApplicationVO> list=applicationService.searchApplication(query);
        return JsonResult.ok(list);
    }
    @Operation(summary = "撤销申请单")
    @PostMapping("cancel/{id}")
    @ApiOperationSupport(order = 30)
    public JsonResult cancelApplication(@PathVariable Long id){
        applicationService.cancelApplication(id);
        return JsonResult.ok();
    }
    @Operation(summary = "分配申请车辆")
    @PostMapping("distribute/{applicationId}/{vehicleId}")
    @ApiOperationSupport(order = 40)
    public JsonResult distribute(@PathVariable Long applicationId,@PathVariable Long vehicleId){
        log.debug("applicationId:{}",applicationId);
        log.debug("vehicleId:{}",vehicleId);
        applicationService.distribute(applicationId, vehicleId);
        return JsonResult.ok();
    }
    @Operation(summary = "归还车辆")
    @PostMapping("back/{applicationId}/{vehicleId}")
    @ApiOperationSupport(order = 50)
    public JsonResult backVehicle(@PathVariable Long applicationId,@PathVariable Long vehicleId){
        log.debug("applicationId={}",applicationId);
        log.debug("vehicleId={}",vehicleId);
        applicationService.back(applicationId,vehicleId);
        return JsonResult.ok();
    }
}